﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using GlobalGameClasses;

namespace SpecialEffects
{
    public class BasicExplosion : Explosion
    {
        
        public VertexExplosion[] explosionVertices
        {
            get;
            private set;
        }

        public float particleSize
        {
            get;
            private set;
        }

        public Vector3 objectDirection
        {
            get;
            private set;
        }

        public Texture2D explosionTexture
        {
            get;
            private set;
        }

        public bool smoke
        {
            get;
            private set;
        }

        public ISoundPlayer soundPlayer = GlobalGameValues.Values.soundPlayer;      


        private BasicExplosion(Vector3 startPos, Vector3 objectDirection, float birthTime, float maxTime, int particleCount, float particleSize, float totalSize, Texture2D explosionTexture, SoundEffect explosionSound, bool smoke)
        {
            this.startPos = startPos;
            this.objectDirection = objectDirection;
            this.birthTime = birthTime;
            this.maxTime = maxTime;
            this.particleCount = particleCount;
            this.particleSize = particleSize;
            this.totalSize = totalSize;
            this.explosionTexture = explosionTexture;
            this.explosionSound = explosionSound;
            this.smoke = smoke;
            this.device = GlobalGameClasses.GlobalGameValues.Values.graphicsDevice;
            this.rand = new Random();
            hasFinished = false;

            CreateExplosionVertices(birthTime);
        }

        #region Static factory methods for basic explosion effects

        /// <summary>
        /// Creates a normal explosion of the player ship.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the player ship.</returns>
        public static BasicExplosion CreateExpl_Player(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("normalExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find normalExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion player_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 10 * MAX_TIME, (int)(2.5 * EXPL_PARTICLE_GW), 5 * PARTICLE_SIZE_GW, 5 * TOTAL_SIZE_GW, explTexture, explSound, false);
         
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                player_explosion.soundPlayer.PlaySound(sound);
            }
            return player_explosion;
        }

        /// <summary>
        /// Creates a blue explosion of enemy ship 1.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the enemy1 ship.</returns>
        public static BasicExplosion CreateExpl_Enemy1(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("blueExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find blueExplosion Texture");
            SoundEffect explSound;
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion enemy1_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 8 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                enemy1_explosion.soundPlayer.PlaySound(sound);
            }
            return enemy1_explosion;
        }

        /// <summary>
        /// Creates a green explosion of enemy ship 2.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the enemy2 ship.</returns>
        public static BasicExplosion CreateExpl_Enemy2(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("greenExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find greenExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion enemy2_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 8 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                enemy2_explosion.soundPlayer.PlaySound(sound);
            }
            return enemy2_explosion;
        }

        /// <summary>
        /// Creates a purple explosion of enemy ship 3.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the enemy3 ship.</returns>
        public static BasicExplosion CreateExpl_Enemy3(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("purpleExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find purpleExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion enemy3_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 8 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, explTexture, explSound, false);
           
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                enemy3_explosion.soundPlayer.PlaySound(sound);
            }
            return enemy3_explosion;
        }

        /// <summary>
        /// Creates a red explosion of enemy ship 4.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the enemy4 ship.</returns>
        public static BasicExplosion CreateExpl_Enemy4(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("redExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find redExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion enemy4_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 8 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, explTexture, explSound, false);
           
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                enemy4_explosion.soundPlayer.PlaySound(sound);
            }
            return enemy4_explosion;
        }

        /// <summary>
        /// Creates a yellow explosion of enemy ship 5.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the enemy5 ship.</returns>
        public static BasicExplosion CreateExpl_Enemy5(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("yellowExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find yellowExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion enemy5_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 8 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                enemy5_explosion.soundPlayer.PlaySound(sound);
            }
            return enemy5_explosion;
        }

        /// <summary>
        /// Creates an explosion of the boss ship.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the boss ship.</returns>
        public static BasicExplosion CreateExpl_Boss(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("normalExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find normalExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion boss_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 20 * MAX_TIME, (int)(5 * EXPL_PARTICLE_GW), 10 * PARTICLE_SIZE_GW, 10 * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                boss_explosion.soundPlayer.PlaySound(sound);
            }
            return boss_explosion;
        }

        /// <summary>
        /// Creates a blue explosion of the laser weapon when it hits an enemy.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the laser weapon.</returns>
        public static BasicExplosion CreateExpl_Laser(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("blueExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find blueExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion laser_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 5 * MAX_TIME, 1 * EXPL_PARTICLE_GW, 2f * PARTICLE_SIZE_GW, 2f * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                laser_explosion.soundPlayer.PlaySound(sound);
            }
            return laser_explosion;
        }

        /// <summary>
        /// Creates a normal explosion of the plasma weapon when it hits an enemy.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the plasma weapon.</returns>
        public static BasicExplosion CreateExpl_Plasma(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("normalExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find normalExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion plasma_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 5 * MAX_TIME, 1 * EXPL_PARTICLE_GW, 2f * PARTICLE_SIZE_GW, 2f * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                plasma_explosion.soundPlayer.PlaySound(sound);
            }
            return plasma_explosion;
        }

        /// <summary>
        /// Creates a normal explosion of a missile when it hits an enemy.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>An explosion of the missile weapon.</returns>
        public static BasicExplosion CreateExpl_Missile(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D explTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("normalExplosion", out explTexture))
                throw new System.ArgumentException("Couldn't find normalExplosion Texture");
            SoundEffect explSound;
            if (!GlobalGameValues.Values.content.GameSounds.TryGetValue("explosionSound", out explSound))
                throw new System.ArgumentException("Couldn't find explosionSound SoundEffect");
            BasicExplosion missile_explosion = new BasicExplosion(startPos, objectDirection, birthTime, 5 * MAX_TIME, 1 * EXPL_PARTICLE_GW, 2f * PARTICLE_SIZE_GW, 2f * TOTAL_SIZE_GW, explTexture, explSound, false);
            
            if (explSound != null)
            {
                SoundEffectInstance sound = explSound.CreateInstance();
                sound.Volume = GlobalGameValues.Values.volume_soundEffect / 100f;
                missile_explosion.soundPlayer.PlaySound(sound);
            }
            return missile_explosion;
        }

        /// <summary>
        /// Creates the smoke for the explosion of the player ship
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>A smoke explosion of the player ship.</returns>
        public static BasicExplosion CreateSmokeExpl_Player(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D smokeExplTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("smokeTexture", out smokeExplTexture))
                throw new System.ArgumentException("Couldn't find smokeTexture Texture");

            BasicExplosion smokeExplosion_player = new BasicExplosion(startPos, objectDirection, birthTime, 15 * MAX_TIME, 1 * EXPL_PARTICLE_GW, 5 * PARTICLE_SIZE_GW, 5 * TOTAL_SIZE_GW, smokeExplTexture, null, true);

            return smokeExplosion_player;
        }

        /// <summary>
        /// Creates the smoke for the explosion of an enemy ship
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>A smoke explosion of the enemy ship.</returns>
        public static BasicExplosion CreateSmokeExpl_Enemy(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D smokeExplTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("smokeTexture", out smokeExplTexture))
                throw new System.ArgumentException("Couldn't find smokeTexture Texture");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion smokeExplosion_enemy = new BasicExplosion(startPos, objectDirection, birthTime, 10 * MAX_TIME, 2 * EXPL_PARTICLE_GW, 3 * PARTICLE_SIZE_GW, 3 * TOTAL_SIZE_GW, smokeExplTexture, null, true);

            return smokeExplosion_enemy;
        }

        /// <summary>
        /// Creates the smoke for the explosion of the boss
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>A smoke explosion of the boss ship.</returns>
        public static BasicExplosion CreateSmokeExpl_Boss(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D smokeExplTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("smokeTexture", out smokeExplTexture))
                throw new System.ArgumentException("Couldn't find smokeTexture Texture");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion smokeExplosion_boss = new BasicExplosion(startPos, objectDirection, birthTime, 40 * MAX_TIME, (int)(5 * EXPL_PARTICLE_GW), 10 * PARTICLE_SIZE_GW, 10 * TOTAL_SIZE_GW, smokeExplTexture, null, true);

            return smokeExplosion_boss;
        }

        /// <summary>
        /// Creates smoke explosion of a weapon when it hits an object.
        /// </summary>
        /// <param name="startPos">The position of the caller.</param>
        /// <param name="objectDirection">The moving direction of the caller.</param>
        /// <param name="birthTime">The current time when this effect is created.</param>
        /// <returns>A smoke explosion of a default weapon.</returns>
        public static BasicExplosion CreateSmokeExpl_Weapon(Vector3 startPos, Vector3 objectDirection, float birthTime)
        {
            Texture2D smokeLaserLaunchTexture;
            if (!GlobalGameValues.Values.content.Textures.TryGetValue("smokeTexture", out smokeLaserLaunchTexture))
                throw new System.ArgumentException("Couldn't find smokeTexture Texture");
            if(objectDirection != Vector3.Zero) objectDirection.Normalize();
            BasicExplosion laserLaunch_smoke = new BasicExplosion(startPos, objectDirection, birthTime, 7 * MAX_TIME, 1 * EXPL_PARTICLE_GW, 2f * PARTICLE_SIZE_GW, 2f * TOTAL_SIZE_GW, smokeLaserLaunchTexture, null, true);

            return laserLaunch_smoke;
        }

        #endregion

        /// <summary>
        /// Creates the vertices for the explosion particles.
        /// </summary>
        /// <param name="birthTime">The given birthTime is the current total elapsed game time in milliseconds.</param>
        private void CreateExplosionVertices(float birthTime)
        {
            //Creates an array that can hold all vertices. Each particle need 6 vertices for two triangles.
            int particles = particleCount;
            explosionVertices = new VertexExplosion[particles * 6];

            int i = 0;
            for (int partnr = 0; partnr < particles; partnr++)
            {
                //the position of the center of the explosion
                Vector3 startingPos = startPos;

                //random moving direction with equal length (normalize)
                float r1 = (float)rand.NextDouble() - 0.5f; //range [-0.5, 0.5]
                float r2 = (float)rand.NextDouble() - 0.5f;
                float r3 = (float)rand.NextDouble() - 0.5f;
                Vector3 randomDirection = new Vector3(r1, r2, r3);
                randomDirection.Normalize();

                //random value to adjust speed and size of the particle
                float randomValue = (float)rand.NextDouble();
                randomValue = (randomValue / 4.0f) * 3.0f + 0.25f; //range [0.25, 1.0]

                //create the vertices for each particle
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(1, 1), birthTime, maxTime, randomValue, totalSize, particleSize);
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(0, 0), birthTime, maxTime, randomValue, totalSize, particleSize);
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(1, 0), birthTime, maxTime, randomValue, totalSize, particleSize);
                
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(1, 1), birthTime, maxTime, randomValue, totalSize, particleSize);
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(0, 1), birthTime, maxTime, randomValue, totalSize, particleSize);
                explosionVertices[i++] = new VertexExplosion(startPos, objectDirection, randomDirection, new Vector2(0, 0), birthTime, maxTime, randomValue, totalSize, particleSize);
            }

            //Copy vertices to device buffer
            deviceVertexBuffer = new VertexBuffer(device, VertexExplosion.vertexDeclaration, explosionVertices.Length, BufferUsage.WriteOnly);
            deviceVertexBuffer.SetData(explosionVertices);
        }
        
        /// <summary>
        /// Draws the explosion effects with a given shader.
        /// </summary>
        /// <param name="shader">The given shader. It should be prepared by the View class.</param>
        public override void Draw(Effect shader)
        {
            if (!hasFinished)
            {
                
                shader.Parameters["xExplosionTexture"].SetValue(explosionTexture);
                foreach (EffectPass pass in shader.CurrentTechnique.Passes)
                {
                    pass.Apply();
                }

                if (smoke)
                {
                    device.BlendState = BlendState.AlphaBlend;
                }
                else
                {
                    device.BlendState = BlendState.Additive;
                }

                device.DepthStencilState = DepthStencilState.None;
                device.DrawUserPrimitives<VertexExplosion>(PrimitiveType.TriangleList, explosionVertices, 0, explosionVertices.Length / 3, VertexExplosion.vertexDeclaration);
                device.DepthStencilState = DepthStencilState.Default;
                device.BlendState = BlendState.Opaque;
            }
        }

        /// <summary>
        /// Checks whether the explosion has finished.
        /// </summary>
        public override void Update()
        {
            if (!hasFinished)
            {
                HasFinished();
            }
        }

        
        /// <summary>
        /// Checks whether the lifetime of an explosion has reached its maximum.
        /// </summary>
        /// <returns>true, if the explosion effect has finished, false otherwise.</returns>
        public override bool HasFinished()
        {
            float currentTime = (float)GlobalGameValues.Values.gameTime.TotalGameTime.TotalMilliseconds;

            if ((currentTime - birthTime) > maxTime)
            {
                explosionVertices = null;
                deviceVertexBuffer.Dispose();
                deviceVertexBuffer = null;
                hasFinished = true;
                return true;
            }

            return false;
        }


    }
}

